<?php
	
	/**
	 * 转帐
	 * @param int $pTransferType;//转账类型 1确认转账 2 取消转账
	 * @param int $deal_id  标的id	 
	 * @param string $ref_data 逗号分割的, 1：投资,填还款日期(int)  ; 2代偿，3代偿还款列表; 4债权转让: id; 5结算担保收益:金额，如果为0,则取fanwe_deal.guarantor_pro_fit_amt ;
	 * @param int $MerCode  商户ID
	 * @param string $cert_md5 
	 * @param string $post_url
	 * @return string
	 */
	function TransferBuAndFreeze($user_id, $tuser_id, $send_user_money, $platformNo,$post_url){
		
		//$pWebUrl= SITE_DOMAIN.APP_ROOT."/index.php?ctl=collocation&act=response&class_name=".COLLNAME."&class_act=DoLoans&from=".$_REQUEST['from']."&repay_start_time=".$repay_start_time;//web方式返回
		//$pS2SUrl= SITE_DOMAIN.APP_ROOT."/index.php?ctl=collocation&act=notify&class_name=".COLLNAME."&class_act=DoLoans&from=".$_REQUEST['from']."&repay_start_time=".$repay_start_time;//s2s方式返回
		
			$user = get_user_info("*","id = ".$user_id);
			$tuser = get_user_info("*","id = ".$tuser_id);
	
			$Sign_data= array();
			
			$Sign_data['ver'] = "0.44";
			$Sign_data['in_cust_no']=$user['mobile'];
			$Sign_data['mchnt_cd']=$platformNo; 
			$Sign_data['mchnt_txn_ssn']=$tuser['id'].ime();
			$Sign_data['out_cust_no']=$tuser['mobile'];
			$Sign_data['amt']= $send_user_money*100;
			$Sign_data['rem']='';
			//amt + "|" + in_cust_no+"|"+ mchnt_cd + "|" + mchnt_txn_ssn+"|"+ out_cust_no +"|"+ rem
			
			ksort($Sign_data);
			$Sign_old = '';
			foreach($Sign_data as $k => $v){
				if($k == 'ver'){
					$Sign_old .=$v;
					$Sign_old_a .=$k;
				}else{
					$Sign_old .= $v."|";
					$Sign_old_a .= $k."+|+";
				}
			}
			/* 签名数据 */
			$pSign=rsaSign($Sign_old,PRIVATE_KEY_PATH);
			
			/* 请求参数 */  
			$req = http_build_query($Sign_data)."&signature=".urlencode($pSign);

			$fuioupay_log = array();
			$fuioupay_log['code'] = 'transferBuAndFreeze';
			$fuioupay_log['create_date'] = to_date(TIME_UTC,'Y-m-d H:i:s');
			$fuioupay_log['strxml'] = $req;
			$GLOBALS['db']->autoExecute(DB_PREFIX."fuioupay_log",$fuioupay_log);
			$log_id = $GLOBALS['db']->insert_id();

			/* 调用账户查询服务 */
			$options = array(
				CURLOPT_POST => TRUE,
				CURLOPT_RETURNTRANSFER => TRUE,
				CURLOPT_SSL_VERIFYPEER=>0,
				CURLOPT_SSL_VERIFYHOST=>0,
				CURLOPT_POSTFIELDS =>$req,
			
			); 
		    $ch = curl_init($post_url); 
		    curl_setopt_array($ch,$options); 
		   	$resultStr = curl_exec($ch);
		    curl_close($ch); 
					
			$result = array();
 			if (empty($ch)){
				//
			}else{
				require_once APP_ROOT_PATH.'system/collocation/fuioupay/xml.php';
				$str3ParaInfo = @XML_unserialize($resultStr);
				$str3Req = $str3ParaInfo['ap']['plain'];
				$result = array();
				$result['resp_code'] = $str3Req["resp_code"];
				$result['mchnt_cd'] = $str3Req["mchnt_cd"];
				$result['mchnt_txn_ssn'] = $str3Req["mchnt_txn_ssn"];
				$result['amt'] = $str3Req["amt"];
				$result['suc_amt'] = $str3Req["suc_amt"];
				$result['signature'] =  $str3ParaInfo['ap']['signature'];

				if($str3Req["resp_code"] =='0000')
				{
					$result['status'] = 1;
					return $result;
					
				}else{
					$result['status'] = 0;
					return $result;
				}
			}
	}
	
?>